SpaceWidget=OpenLayers.Class(BaseWidget,{
	sketchSymbolizers: null,
 	style : null,
 	styleMap : null,
 	measureControls : null,
	initialize : function() {
		this.sketchSymbolizers={
                "Point": {
                    pointRadius: 4,	
                    graphicName: "square",
                    fillColor: "white",
                    fillOpacity: 1,
                    strokeWidth: 1,
                    strokeOpacity: 1,
                    strokeColor: "#333333"
                },
                "Line": {
                    strokeWidth: 3,
                    strokeOpacity: 1,
                    strokeColor: "#666666",
                    strokeDashstyle: "dash"
                },
                "Polygon": {
                    strokeWidth: 2,
                    strokeOpacity: 1,
                    strokeColor: "red",
                    fillColor: "white",
                    fillOpacity: 0.3
                }
            };
            this.style=new OpenLayers.Style();
            this.style.addRules([
                new OpenLayers.Rule({symbolizer: this.sketchSymbolizers})
            ]);
            
            this.styleMap=new OpenLayers.StyleMap({"default": this.style});
          
            this.measureControls={
                polygonSearch: new OpenLayers.Control.Measure(
                    OpenLayers.Handler.Polygon, {
                        persist: true,
                        type :'polygon',
                        handlerOptions: {
                            layerOptions: {styleMap: this.styleMap}
                        }
                    }
                ),
                boxSearch : new OpenLayers.Control.Measure(
                    OpenLayers.Handler.RegularPolygon, {
                        persist: true,
                        type :'boxZooOut',
                        handlerOptions: {
                        	irregular: true,
                            layerOptions: {styleMap: this.styleMap}
                        }
                    }
                ),
                circleSearch : new OpenLayers.Control.Measure(
                    OpenLayers.Handler.RegularPolygon, {
                        persist: true,
                        type :'circle',
                        handlerOptions: {
                        	irregular: false,
                        	sides: 40,
                            layerOptions: {styleMap: this.styleMap}
                        }
                    }
                )
            };
            
	},
	getElement : function(){
		if(!this.element){
			if(this.config){
				this.element = this.createElement(this.map);
				for(var key in this.measureControls) {
					var control = this.measureControls[key];
					this.map.addControl(control);
				}
			}
		}
		return this.element;
	},
	createElement : function(){
		var $this=this;
		var SpaceBox=$("<div id='SpaceWidget'></div>");
		if( this.config.top!=null)SpaceBox.css('top' ,this.config.top+'px');
		if( this.config.right!=null)SpaceBox.css('right' ,this.config.right+'px');
		if( this.config.left!=null)SpaceBox.css('left' ,this.config.left+'px');
		if( this.config.bottom!=null)SpaceBox.css('bottom' ,this.config.bottom+'px');
		SpaceBox.addClass('widget-class');
		SpaceBox.css({
			'width' :'423px',
			'height' : '35px',
			'font-size' :'12px',
			'background-color':'transparent'
		});
		var SpaceBoxBar=$('<div class="SpaceBar">'+
				'<button class="toggleControl" name="boxSearch">拉框查询</button>'+
		        '<button class="toggleControl" name="polygonSearch">多边形查询</button>'+
				'<button class="toggleControl" name="circleSearch">缓冲区查询</button>'+
				'<button class="toggleControl" name="point-round-search">点周边查询</button>'+
			'</div>');
		SpaceBoxBar.buttonset();
		SpaceBoxBar.find('.toggleControl').click(function(){
			var name=$(this).attr('name');
			$this.toggleControl(name);
		});
		var table=$(
			'<table width="100%" height="100%" cellpadding=0 cellspacing=0>'+
	    		'<tr>'+
	    			'<td class="left"></td>'+
	    			'<td class="center"><div class="tool-bar"></div></td>'+
	    			'<td class="right"></td>'+
	    		'</tr>'+
	    		'<tr class="bottom">'+
	    			'<td colspan="3"></td>'+
	    		'</tr>'+
	    	'</table>'
    	   );
    	table.css({
			
    	}).find(".bottom").css({
			'height': '1px',
			'background-image': 'url("images/custom/window/top-bottom.png")',
			'background-repeat': 'repeat-x'
    	}).end().find('.center').css({
    		'background-position' :'top',
			'background-image': 'url("images/custom/window/top-bottom.png")',
			'background-repeat': 'repeat-x'
    	}).end().find('.left').css({
    		'width' : '6px',
			'background-image': 'url("images/custom/window/left-corners.png")'
    	}).end().find('.right').css({
    		'width' : '6px',
			'background-image': 'url("images/custom/window/right-corners.png")'
    	}).end().find(".tool-bar").append(SpaceBoxBar);
    	
		//SpaceBox.append(table);
		
		SpaceBoxBar.css({
			'font-size' :'12px'
		});
		SpaceBox.append(SpaceBoxBar);
		return SpaceBox;
	},
	toggleControl : function(type){
		for(key in this.measureControls) {
              var control = this.measureControls[key];
              if(type == key ) {
                  control.activate();
              } else {
                  control.deactivate();
              }
        }
	},
	CLASS_NAME:"openGis.SpaceWidget"
});